import pandas as pd
from pandas import Series,DataFrame
import numpy as np
import requests
from flask import Flask,render_template
from openpyxl import Workbook
from bokeh.embed import components
from bokeh.resources import INLINE
import json
from run import one,two,wu,three,four,six,seven,eight,nine,ten,eleven,twelve,fourteen,fifteen


app= Flask(__name__)

@app.route('/index')
def helle_world():
    url='https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=localCityNCOVDataList,diseaseh5Shelf'
    response = requests.get(url, verify=False)
    json_data = response.json()
    update_time=json_data['data']['diseaseh5Shelf']['chinaTotal']['mtime']
    return render_template(
    'index2.html',update_time=update_time,a='active'
    )

@app.route('/')
def index():
    url2='https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=chinaDayListNew,chinaDayAddListNew&limit=30'
    response = requests.get(url2, verify=False)
    json_data = response.json()
    json_data['data']
    date=[]
    confirm=[]
    dead=[]
    heal=[]
    localadd=[]
    localcomfirm=[]
    data=json_data['data']['chinaDayAddListNew']
    for i in range(len(data)):
        date.append(data[i]['date'])
        confirm.append(data[i]['confirm'])
        dead.append(data[i]['dead'])
        heal.append(data[i]['heal'])
        localadd.append(data[i]['localinfectionadd'])
        localcomfirm.append(data[i]['localConfirmadd'])
    rq=[]
    for i in range(30):
        year=data[i]['y']
        rq.append(year+'-'+date[i].replace('.','-'))
    df={
    '日期':rq,
    '确诊':confirm,
    '死亡':dead,
    '康复':heal,
    '新增无症状':localadd,
    '新增确诊':localcomfirm
}
    df = DataFrame(df)
    return df
@app.route('/bar')
def bar():
    a=one()[0]
    b=one()[1]
    c=one()[2]
    return render_template(
    'index.html',rl=a,q='active',the_titles=b,
        the_contents=c,wz='红色柱体为感染>康复的人数，绿色主体为康复>感染的人数，通过该图能了解目前我国疫情现状，推测疫情的趋势'
    )
@app.route('/wzz')
def wzz():
    p=two()[0]
    df=two()[1]
    js_resources=INLINE.render_js()
    css_resources=INLINE.render_css()
    script,div=components(p)
    titles=('序号','日期','新增无症状人数')
    日期=df['日期'].to_list()
    新增无症状=df['新增无症状'].to_list()
    contents=[]
    for i in range(len(日期)):
        contents.append([i])
    for a in range(len(日期)):
        contents[a].append(日期[a])
        contents[a].append(新增无症状[a])
    return render_template(
    'index.html',
    plot_script =script,
    plot_div = div,
    js_resources = js_resources,
    css_resources = css_resources,the_titles=titles,
        the_contents=contents,
        b='active'
    )


@app.route('/kanfu')
def kanfu():
    p=three()[0]
    df=three()[1]
    js_resources=INLINE.render_js()
    css_resources=INLINE.render_css()
    script,div=components(p)
    titles=('序号','日期','累计确诊数量','康复人数')
    日期=df['日期'].to_list()
    康复=df['康复'].to_list()
    确诊=df['确诊'].to_list()
    contents=[]
    for i in range(len(日期)):
        contents.append([i])
    for a in range(len(日期)):
        contents[a].append(日期[a])
        contents[a].append(确诊[a])
        contents[a].append(康复[a])
    return render_template(
    'index.html',
    plot_script =script,
    plot_div = div,
    js_resources = js_resources,
    css_resources = css_resources,the_titles=titles,
        the_contents=contents,
        e='active'
    )

@app.route('/rl')
def rl():
    a=four()[0]
    b=four()[1]
    c=four()[2]
    return render_template(
    'index.html',rl=a,a='active',the_titles=b,
        the_contents=c,wz='目前，累计确诊最多的省份为台湾、湖北、吉林，累计疫情数量与病毒突然的爆发有关，但目前本土疫情已经受到控制，而台湾疫情情况较为严重，累计数量任会有较大的上升。'
    )
 
@app.route('/sw')
def sw():
    p=fourteen()[0]
    df=fourteen()[1]
    js_resources=INLINE.render_js()
    css_resources=INLINE.render_css()
    script,div=components(p)
    titles=('序号','日期','新冠死亡人数数量')
    日期=df['日期'].to_list()
    死亡=df['死亡'].to_list()
    contents=[]
    for i in range(len(日期)):
        contents.append([i])
    for a in range(len(日期)):
        contents[a].append(日期[a])
        contents[a].append(死亡[a])
    return render_template(
    'index.html',
    plot_script =script,
    plot_div = div,
    js_resources = js_resources,
    css_resources = css_resources,the_titles=titles,
        the_contents=contents,
        d='active'
    )



# @app.route('/top')
# def top():
#     a=six()[0]
#     b=six()[1]
#     c=six()[2]
#     return render_template(
#         'index.html',rl=a,t='active',the_titles=b,
#             the_contents=c
#         )



@app.route('/qz')
def qz():
    p=fifteen()[0]
    df=fifteen()[1]
    js_resources=INLINE.render_js()
    css_resources=INLINE.render_css()
    script,div=components(p)
    titles=('序号','日期','新冠确诊人数数量')
    日期=df['日期'].to_list()
    死亡=df['新增确诊'].to_list()
    contents=[]
    for i in range(len(日期)):
        contents.append([i])
    for a in range(len(日期)):
        contents[a].append(日期[a])
        contents[a].append(死亡[a])
    return render_template(
    'index.html',
    plot_script =script,
    plot_div = div,
    js_resources = js_resources,
    css_resources = css_resources,the_titles=titles,
        the_contents=contents,
        c='active'
    )
@app.route('/db1')
def db1():
    a=seven()[0]
    b=seven()[1]
    c=seven()[2]
    return render_template(
        'index.html',rl=a,f='active',the_titles=b,
            the_contents=c,wz='由此可见，我国的主要疫情病例为无症状感染'
        )

@app.route('/rose')
def rose():
    a=eight()[0]
    b=eight()[1]
    c=eight()[2]
    d=eight()[3]
    return render_template(
        'index.html',rl=a,g='active',the_titles=b,
            the_contents=c,wz=d
        )

@app.route('/vaccine')
def vaccine():
    a=nine()[0]
    b=nine()[1]
    c=nine()[2]
    return render_template(
        'index.html',rl=a,h='active',the_titles=b,
            the_contents=c,wz='此图标统计了接种疫苗数量最多的国家的前30位，有上方图标可见，目前中国和印度的疫苗接种的数量最多，从该层面上一定程度说明疫苗接受率高，但该情况也会收到国家的人口数量有所影响，单国家接种疫苗数量统计如下'
        )

@app.route('/jw')
def jw():
    a=ten()[0]
    b=ten()[1]
    c=ten()[2]
    return render_template(
        'index.html',rl=a,j='active',the_titles=b,
            the_contents=c,wz='目前我国境外输入病例控制较好，每日输入在50日以下，对外防疫措施做得很好'
        )
@app.route('/v2')
def v2():
    a=eleven()[0]
    b=eleven()[1]
    c=eleven()[2]
    return render_template(
        'index.html',rl=a,i='active',the_titles=b,
            the_contents=c,wz="目前市面上的疫苗种类共有23种，但绝大多数的国家使用的是牛津/阿斯利康疫苗和辉瑞/BioNTech疫苗，以下是所有种类疫苗被国家选用的数量统计情况。"
        )
@app.route('/p')
def p():
    a=twelve()[0]
    b=twelve()[1]
    c=twelve()[2]
    return render_template(
        'index.html',rl=a,p='active',the_titles=b,
            the_contents=c,wz="从该数据来看，人口与病毒感染数量没有必然的关系。可能在未知期，人口基数大的国家，病毒爆发的几率更大，但只要做好预防措施，或有良好的预防政策，可在一定程度上对病毒的传播进行抑制"
        )

@app.route('/five')
def five():
    a=wu()[0]
    b=wu()[1]
    c=wu()[2]
    return render_template(
        'index.html',rl=a,s='active',the_titles=b,
            the_contents=c,wz="美国的疫情最为严重，确诊数量将近为累计确诊数量前15的国家总和的1/4"
        )
    


    
if __name__ == '__main__':
    app.run()